#ifndef __HTTPREQUEST_H__
#define __HTTPREQUEST_H__

#include <string>
#include <map>
#include "httpparsestate.h"

namespace tiny_muduo
{
    static constexpr char http[] = "HTTP/1.";

    enum Method
    {
        kGet,
        kPost,
        kPut,
        kDelete,
        kTrace,
        kOptions,
        kConnect,
        kPatch,
    };

    enum Version
    {
        kUnknown,
        kHttp10,
        kHttp11,
    };

    class HttpRequest
    {
    public:
        HttpRequest();
        ~HttpRequest();

        bool ParseRequestMethod(const char* start, const char* end);

        bool ParseRequestLine(const char* start, const char* end);

        bool ParseHeaders(const char* start, const char* colon, const char* end);

        bool ParseBody(const char* start, const char* end);

        Method method() const { return method_; }
        const std::string& path() const { return path_; }
        const std::string& query() const { return query_; }
        Version version() const { return version_; }
        
        const std::map<std::string, std::string>& headers() const { return headers_; }
        
        void Swap(HttpRequest& req);

        std::string GetHeader(const std::string_view header) const 
        {
            std::string ret;
            auto iter = headers_.find(header.data());
            return iter == headers_.end() ? ret : iter->second;
        }

    private:
        Method method_;
        std::string path_;
        std::string query_;
        Version version_;
        std::map<std::string, std::string> headers_;
    };
}

#endif
